package com.frame.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.frame.domain.Permission;
import com.frame.domain.UserRole;
import com.mini.core.Record;
import com.mini.core.dao.MiniDao;

/**
 * DAO for {@link USERROLE}.
 */
@Service
public class UserRoleService{
	@Autowired
	MiniDao miniDao;
	
	/**
	 * 查找所有角色
	 * @return
	 */
	public List<Record> findByUserId(String userid){
		String sql = "SELECT r.*,ur.ID as userroleid FROM ROLE r LEFT JOIN (SELECT * FROM USER_ROLE WHERE USERID=?) ur ON r.id=ur.ROLEID ";
		return miniDao.findList(sql, Record.class,userid);
	}

	/**
	 * 根据用户主键删除用户角色关系表数据
	 * @param userid
	 */
	public void deleteByUserid(String userid) {
		String sql = "DELETE FROM USER_ROLE WHERE USERID=?";
		miniDao.execute(sql, userid);
	}

	/**
	 * 保存角色关系表
	 * @param userRole
	 */
	public void save(UserRole userRole) {
		miniDao.insert(userRole);
	}
}
